package com.dys.controller;

import org.springframework.web.bind.annotation.*;

/**
 * @className: com.dys.controller.AnnoController
 * @description: SpringMVC_常见注解
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/10/26 20:57
 */
@RestController
public class AnnoController {

    @RequestMapping(value = {"/requestParams.do"})
    public String requestParams(@RequestParam(name = "username", required = false) String name, @RequestParam(value = "password") String pwd) {
        System.out.println("请求参数: username: " + name);
        System.out.println("请求参数：: password: " + pwd);
        return "request param success";
    }

    @RequestMapping("/getPathVariable/{userId}/{username}")
    public String getPathVariable(@PathVariable("userId") Integer id, @PathVariable("username") String username) {
        System.out.println("id:" + id);
        System.out.println("username:" + username);
        System.out.println("testPathVariable1");
        return "URL参数获取成功!";
    }

    @RequestMapping(value = {"/getRequestHeaders.do"})
    public String getRequestHeaders(@RequestHeader(value = "Accept", required = false) String accept) {
        System.out.println(accept);
        return "request headers success";
    }

    @RequestMapping("/getCookie")
    public String getCookie(@CookieValue(value = "JSESSIONID", required = false) String cookieValue) {
        System.out.println(cookieValue);
        return "success";
    }
}
